import express from 'express';
const router = express.Router();

import PublicController from '@src/controller/PublicController'
import validateGlobal from '@src/middleware/validate';
import Joi from 'joi';
import Paths from '@src/common/Paths';
import { validateEmail } from '@src/middleware/validateCode';
import singleFileUpload from '@src/util/multer'

router.post(Paths.Apis.Code, validateGlobal(
    Joi.object({
        email: Joi.string().email().required().messages({
            'string.email': '邮箱格式错误',
            'any.required': '邮箱不能为空'
        }),
        type: Joi.string()
    })
), validateEmail, PublicController.code);

router.post(Paths.Apis.Upload, singleFileUpload('avatar'), PublicController.upload);

export default router;
